package com.training.food.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.training.food.Mapper.UserMapper;
import com.training.food.pojo.User;
import com.training.food.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegisterServiceImpl extends ServiceImpl<UserMapper, User> implements RegisterService {
    @Autowired
    UserMapper userMapper;
    @Override
    public boolean findByUsername(String username) {
         User user = userMapper.findByUsername(username);
         if(user==null){
             return false;
         }
         return true;
    }
    @Override
    public boolean save(User user){
        if(!findByUsername(user.getUsername())){
            userMapper.insert(user);
            return true;
        }
        return false;
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }
}
